package edu.ccut.saturn.studio.dialog.componentdialog;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.widgets.Shell;

import edu.ccut.saturn.studio.dialog.ParentPrimaryDialog;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnComponentNode;
import edu.ccut.saturn.studio.util.ConversionUtil;

public class SaturnComponentDialog extends ParentPrimaryDialog {

private SaturnComponentNode saturnComponentNode;
	
	public SaturnComponentDialog(Shell parentShell, SaturnComponentNode saturnComponentNode){
		super(parentShell, saturnComponentNode);
		this.saturnComponentNode = saturnComponentNode;
	}

	@Override
	protected void initialization() {
		super.expressionText.setText(saturnComponentNode.getKey().trim());
		super.tableViewer.setInput(ConversionUtil.scopeMapFromXmlToSurface(super.parameterlist));
	}

	@Override
	protected void buttonPressed(int buttonId) {
		if (parameterlist == null) {
			return;
		}
		if (buttonId == IDialogConstants.OK_ID) {
			saturnComponentNode.setKey(super.expressionText.getText().trim());
			saturnComponentNode.setDescription(super.descriptionText.getText().trim());
			ConversionUtil.scopeMap(super.parameterlist);
			saturnComponentNode.setParameters(super.parameterlist);
			saturnComponentNode.setName(super.nameText.getText().trim());
		}
		super.buttonPressed(buttonId);
	}
}
